<template>
<div class="bh-checkbox-group">
	<slot></slot>
</div>
</template>

<script>
export default {
	name: 'bh-checkbox-group',
	componentName: 'BHCheckboxGroup',
	props: {
		disabled: Boolean,
		value: {},
		label: {},
		size: String,
		min: Number,
		max: Number,
	},
	computed: {
	},
	methods: {
		handleChange(value) {
			this.$nextTick(() => {
				this.$emit('input', value);
				this.$emit('change', value);
			});
		},
		handleCheckboxClick(label, checked) {
			let list = JSON.parse(JSON.stringify(this.value));
			let flag1 = list.includes(label);

			if(flag1 && !checked) {//存在,取消
				let index = list.indexOf(label);
				list.splice(index, 1);
			}else if(!flag1 && checked) {//不存在
				list.push(label);
			}
			
			this.handleChange(list);
		},
	},
	created() {
		this.$on('handleCheckboxClick', this.handleCheckboxClick);
	},
}
</script>
